<?php

namespace App\Services\Task;

class TaskService22
{
    public static function notify($param){

        $policyInterface = resolve('App\Repositories\Contracts\PolicyInterface');

        $where = [
            'airline'   => $param['hs_code']
        ];

        $policy = $policyInterface->index($where);
        if ($policy) {

            switch ($policy['product_type']) {

                case 12: {
                    $ctripRulePolicyInterface = resolve('App\Repositories\Ota\Ctrip\Policy\Contracts\CtripRulePolicyInterface');
                    $deleteRes = $ctripRulePolicyInterface->delete([$policy['policy_code']],'ByCode');
                    if ($deleteRes && isset($deleteRes['TradeResult'])){
                        if (isset($uploadRes['TradeResult']['Result']) && isset($uploadRes['TradeResult']['Result']['SuccessList'])) {

                            $rulePolicyInterface = resolve('App\Repositories\Contracts\RulePolicyInterface');
                            $rulePolicyInterface->update(['policy_code'=>$policy['policy_code']],['status'=>3]);

                            return true;
                        }

                        return $deleteRes['TradeResult']['ErrorList'] ? $deleteRes['TradeResult']['ErrorList'][0]['ErrorMessage'] :  '删除失败：政策ID：'.$deleteRes['TradeResult']['Result']['FailedList'][0];
                    } else {

                        return '网络有问题，稍后重试';
                    }
                }

                case 40: {
                    $tcPolicyInterface = resolve('App\Repositories\Ota\Tc\Policy\Contracts\TcPolicyInterface');
                    $deleteRes = $tcPolicyInterface->deleteSpecial([$policy['policy_code']],2);
                    logger($deleteRes);
                    if ($deleteRes){

                        $rulePolicyInterface = resolve('App\Repositories\Contracts\RulePolicyInterface');
                        $rulePolicyInterface->update(['policy_code'=>$policy['policy_code']],['status'=>3]);

                        return true;

                    } else {

                        return '网络有问题，稍后重试';
                    }
                }
            }

        }

    }
}